package com.rms.hkpc.dialog;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;

import com.rms.hkpc.R;

public class CommDialogUtils {
    private static ProgressDialog progressDialog;

    public interface DialogClickListener {
        void cancelClick();

        void okClick();
    }

    public interface OnItemClickListener {
        void onItemClick(View v, Object obj);
    }

    public static void showProgressDialog(Context context) {
        // 展示進度條
        progressDialog = new ProgressDialog(context);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setTitle(R.string.downloading);
        progressDialog.setMax(100);
        progressDialog.setCancelable(false);
        progressDialog.show();
    }

    public static void setProgress(int progress) {
        progressDialog.setProgress(progress);
    }

    public static void dismissProDialog() {
        progressDialog.dismiss();
    }

    public static void showDialog(Context context, String title, String message, int positiveText, final DialogClickListener dialogClickListener) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);// 设置标题
        // builder.setIcon(R.drawable.ic_launcher);//设置图标
        builder.setMessage(message);// 为对话框设置内容
        // 为对话框设置取消按钮
        builder.setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                if (dialogClickListener != null) {
                    dialogClickListener.cancelClick();
                }
            }
        });
        builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                if (dialogClickListener != null) {
                    dialogClickListener.okClick();

                }
            }
        });
        try {
            builder.create().show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
